package com.xieyingwangluo.yxpart.logic;


import com.xieyingwangluo.yxpart.bean.PartBean;
import com.xieyingwangluo.yxpart.bean.Result;

import com.xieyingwangluo.yxpart.entity.MerchantModel;
import com.xieyingwangluo.yxpart.entity.PartModel;
import com.xieyingwangluo.yxpart.service.MerchantService;
import com.xieyingwangluo.yxpart.service.PartService;
import com.xieyingwangluo.yxpart.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

@Component
public class PartLogic {
    @Autowired
    private PartService partService;
    @Autowired
    private MerchantService merchantService;
    //兼职信息添加(发布兼职)
    public Result add(
                      PartModel partModel,String times,String timee
    ) {
        partModel.setStart_time(DateUtil.StD(times,"yyyy-MM-dd HH:mm"));
        partModel.setEnd_time(DateUtil.StD(timee,"yyyy-MM-dd HH:mm"));
        partModel.setState(0);//有四个状态:待审核,审核未通过,审核通过,过期了
        partService.add(partModel);
        return Result.generate(0, "Add success", partModel);
    }

    //显示兼职列表信息
    public Result selA(
                       PartModel partModel
    ) {
        List<PartModel> list =  partService.selA(partModel);
        List<PartBean> listB = new ArrayList<PartBean>();
        for (Iterator iterator = list.iterator(); iterator.hasNext();) {
            PartModel p = (PartModel) iterator.next();
            PartBean partBean = new PartBean(p);
            listB.add(partBean);
        }
        return Result.generate(0, "Select success", listB);
    }

    //修改兼职状态
    public Result upd(
                      @RequestParam("noid") String noid,
                      @RequestParam("state") int state
    ) {

        PartModel p = new PartModel();
        p.setNoid(noid);
        p.setState(state);
        partService.update(p);
        return Result.generate(0, "Update success", p);
    }

    //显示兼职信息
    public Result selO(
            String noid
    ) {
        PartModel partModel = partService.selO(noid);
        return Result.generate(0, "Select success", partModel);
    }


}
